﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMasterPage.master" AutoEventWireup="true" CodeFile="dept.aspx.cs" Inherits="Admin_dept" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script>
    $(function () {
        $("#dg tbody tr").hoverIntent(
            function () { $(this).children().css("background-color", "#F2F4F6"); },
            function () { $(this).children().css("background-color", "#FFFFFF"); }
        );
        $('#BtnAdd').click(function (e) {
            $('#Add-modal-content').modal({
                opacity: 55, zIndex: 10,
                onOpen: function (dialog) {
                    dialog.overlay.fadeIn('fast', function () {
                        dialog.data.hide();
                        dialog.container.fadeIn('fast', function () {
                            dialog.data.show(); //slideDown('slow');
                        });
                    });
                }
            });
            return false;
        });
        $("#BtnImport").click(function (e) {
            $('#Import-modal-content').modal({
                opacity: 55, zIndex: 10,
                onOpen: function (dialog) {
                    dialog.overlay.fadeIn('fast', function () {
                        dialog.data.hide();
                        dialog.container.fadeIn('fast', function () {
                            dialog.data.show(); //slideDown('slow');
                        });
                    });
                }
            });
            return false;
        });
    });
</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td align=left><b>部门列表</b></td></tr>
</table>


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td align=left> 
    <a href='#' id='BtnAdd' class="abtn_add">增加部门</a>
    </td></tr>
<tr>
<td>
    <table id="dg" class="grid" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th width=5%></th>
                <th >部门名称</th>
                <th width=15%>操作</th>
            </tr>
        </thead>
        <tbody>
        <asp:Repeater ID="rp" runat="server" EnableViewState=false>
        <ItemTemplate>
            <tr>
                <td></td>
                <td><%# Eval("DepartmentName")%></td>
                <td>
                <a href="#" onclick="EditStu('<%# Eval("DepartmentID")%>','<%# Eval("DepartmentName")%>')">编辑</a> &nbsp;
                <a href="#" onclick='delSingle(<%# Eval("DepartmentID")%>)'>删除</a></td>
            </tr>
        </ItemTemplate>
        </asp:Repeater>
        </tbody>
    </table>
</td>

</tr>
</table>


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
    <table class="grid" border="0" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th>统计：共有 <asp:Label ID="LibStuCount" runat="server" Text="0"></asp:Label>部门 </th>
            </tr>
        </thead>
    </table>
</td>
</tr>
</table>

<div id="Add-modal-content">
    <div class="modal-div">部门名称：<input id="stuNum" type="text" />(必填)</div>
    <div class="modal-div">
    <span style="float:left;margin-left:20px;">
    <input id="Button3" type="button" class="btn" onclick="addNew()" value="增加" />
    <input id="btnCancle" type="button" class="btn" value="取消" onclick="Cancle()" />
    </span>
    <span id="statusAdd" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" />添加中请稍候...
    </span>
    </div>
</div>


<div id='confirm'>
	<div class='header'><span>注意</span></div>
	<div class='message'></div>
	<span id="statusDel" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" />添加中请稍候...
    </span>
	<div class='buttons'>
		<div class='no simplemodal-close'>取消</div>
		<div class='yes'>确定删除</div>
		
	</div>
</div>

<div id="Edit-modal-content">
    <div class="modal-div">部门名称：<input id="EditstuNum" type="text" />(必填) </div>
    <input id="EditstuId" type="hidden" value="" />
    <div class="modal-div">
    <span style="float:left;margin-left:20px;">
    <input id="Button4" type="button" class="btn" onclick="btnEdit()" value="修改" />
    <input id="Button5" type="button" class="btn" value="取消" onclick="Cancle()" />
    </span>
    <span id="statusEdit" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" />修改中请稍候...
    </span>
    </div>
</div>

<script>
    function addNew() {
        var stuNum = $("#stuNum").val();
        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/adddept.aspx",
            data: "deptname=" + stuNum,
            beforeSend: function () {
                $(".status").show();
                $("#btnCancle").attr('disabled', true);
                $("#btnAdd").attr('disabled', true);
            },
            success: function (msg) {
                if (msg == "1") {
                    if (confirm("添加成功,是否继续添加？")) {
                        $("#stuNum").val("");
                    } else {
                        $(".status").hide();
                        $("#btnCancle").attr('disabled', false);
                        $("#btnAdd").attr('disabled', false);
                        $.modal.close();
                        window.location.href = location.href;
                    }
                } else {
                    alert("添加失败！请重新添加.");
                }

            },
            error: function (msg) {
                $(".status").hide();
                $("#btnCancle").attr('disabled', false);
                $("#btnAdd").attr('disabled', false);
                alert("发生错误,请重新添加.");
            }
        });
    }
    function Cancle() {
        $.modal.close();
    }
    function confirm(message, callback) {
        $('#confirm').modal({
            closeHTML: "<a href='#' title='关闭' class='modal-close'>x</a>",
            //position: ["20%", ],
            overlayId: 'confirm-overlay',
            containerId: 'confirm-container',
            onShow: function (dialog) {
                var modal = this;
                $('.message', dialog.data[0]).append(message);
                // if the user clicks "yes"
                $('.yes', dialog.data[0]).click(function () {
                    // call the callback
                    if ($.isFunction(callback)) {
                        callback.apply();
                    }
                    // close the dialog
                    //modal.close(); // or $.modal.close();
                });
            }
        });
    }
    function EditStu(id, stuNum) {
        $('#Edit-modal-content').modal({
            opacity: 55, zIndex: 10,
            onOpen: function (dialog) {
                dialog.overlay.fadeIn('fast', function () {
                    //赋值
                    $("#EditstuId").val(id);
                    $("#EditstuNum").val(stuNum);
                    dialog.data.hide();
                    dialog.container.fadeIn('fast', function () {
                        dialog.data.show(); //slideDown('slow');
                    });
                });
            }
        });
        return false;
    }
    function btnEdit() {
        var stuId = $("#EditstuId").val();
        var stuNum = $("#EditstuNum").val();

        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/Editdept.aspx",
            data: "depid=" + stuId + "&deptname=" + stuNum,
            beforeSend: function () {
                $(".status").show();
                $("#Button4").attr('disabled', true);
                $("#Button5").attr('disabled', true);
            },
            success: function (msg) {
                if (msg == "1") {
                    $.modal.close();
                    window.location.href = location.href;
                } else {
                    alert("修改失败！请重新修改.");
                }

            },
            error: function (msg) {
                $(".status").hide();
                $("#Button4").attr('disabled', false);
                $("#Button5").attr('disabled', false);
                alert("发生错误,请重新修改.");
            }
        });

    }

    function del(id) {
        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/deldept.aspx",
            data: "id=" + id,
            beforeSend: function () {
                $(".status").show();
            },
            success: function (msg) {
                if (msg == "1") { alert("删除成功！");window.location.href = window.location.href; $.modal.close();  } else { alert("删除失败！请重新删除."); $.modal.close(); }
            },
            error: function (msg) {
                alert("发生错误,请重新删除."); $.modal.close();
            }
        });
    }
    function delSingle(id) {
        confirm("你确定要删除选中的部门么?\r\n该操作不可删除。", function () {
            del(id);
        });
    }

</script>

</asp:Content>

